/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
 // 递归
func hasPathSum(root *TreeNode, targetSum int) bool {
    if root == nil {
        return false
    }
    if root.Left == nil && root.Right == nil {
        res := targetSum - root.Val
        if res == 0 {
            return true
        }
        return false
    }
    var isLeftHas, isRightHas bool
    if root.Left != nil {
        targetSum -= root.Val
        isLeftHas = hasPathSum(root.Left, targetSum)
        targetSum += root.Val
    }
    if root.Right != nil {
        targetSum -= root.Val
        isRightHas = hasPathSum(root.Right, targetSum)
        targetSum += root.Val
    }
    if root.Left != nil && root.Right != nil {
        return isLeftHas || isRightHas
    } else if root.Left != nil {
        return isLeftHas
    } else {
        return isRightHas
    }
}